package com.webservice.service.impl;

import com.webservice.model.User;
import com.webservice.service.UserService;
import org.springframework.stereotype.Component;

import javax.jws.WebService;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/***    接口实现类
 * description:
 *      接口实现类名称前的注解 targetNamespace是当前累实现接口所在包名称的反序（ps：加上反斜线）
 *      endpointInterface是当前需要实现接口的全称
 *      D:\F\workspace\ideaproject\webservice_cxf_demo\src\main\java\com\webservice\service
 *      com.webservice.service
 */
@Component
@WebService(serviceName = "UserService",
        targetNamespace = "http://service.webservice.com/",
        endpointInterface = "com.webservice.service.UserService")
public class UserServiceImpl implements UserService {

    private Map<String, User> userMap = new HashMap<>();

    public UserServiceImpl() {
        System.out.println("向实体类插入数据");
        User user = new User();
        user.setUserId("411001");
        user.setUsername("zhangsan");
        user.setAge("20");
        user.setUpdateTime(new Date().toString());
        userMap.put(user.getUserId(), user);

        user = new User();
        user.setUserId("411002");
        user.setUsername("lisi");
        user.setAge("30");
        user.setUpdateTime(new Date().toString());
        userMap.put(user.getUserId(), user);

        user = new User();
        user.setUserId("411003");
        user.setUsername("wangwu");
        user.setAge("40");
        user.setUpdateTime(new Date().toString());
        userMap.put(user.getUserId(), user);

    }

    @Override
    public String getName(String userId) {
        return "liyd-" + userId;
    }

    @Override
    public User getUser(String userId) {
        User user = userMap.get(userId);
        return user;
    }

    @Override
    public ArrayList<User> getAllUser() {
        ArrayList<User> users = new ArrayList<>();
        userMap.forEach((key, value) -> users.add(value));
        return users;
    }
}
